<template>
	<view class="hd-pay-code-container">
    <view class="code-content flex-column">
      <view class="code-txt">
        请输入尾号为{{showTel}}的手机验证码
      </view>
      <rh-code v-model="code" :phonenumber="phonenumber"></rh-code>
    </view>
		<rh-submit-btn text="完成注册" class-name="special" color="#23994f" :submit-action="submit"></rh-submit-btn>
	</view>
</template>

<script>
	import {register} from '@/api/common/index.js'
	export default {
		data() {
			return {
				phonenumber: '',
				code: '',
			}
		},
		computed: {
			showTel(){
				let tel = this.phonenumber || ''
				
				return `****${tel.substring(7)}`
			},
		},
		onLoad() {
			this.phonenumber = uni.getStorageSync('icar-wxtel')
			let _self = this
		},
		methods: {
			submit(val){
				let _self = this, {redirect, a} = this.$route.query, query = {}
				if(redirect == 'hdHome'){
					query.a = (uni.getStorageSync('icar-wxActive') || {}).a
					query.i = (uni.getStorageSync('icar-wxActive') || {}).i
				}
				return new Promise((resolve, reject) => {
					let params = {
						phone: _self.phonenumber,
						code: _self.code
					}
					let wxUser = uni.getStorageSync('icar-wxuser')
					if(!wxUser || !wxUser['openId']) {
						_self.$attention.noIcon('请先进行微信授权')
						resolve(true)
					}else{
						register({...params, ...wxUser}).then(res => {
							let { token } = res.data
							uni.setStorage({
								key: `ICarddWx`,
								data: token,
								success: () => {
									_self.$$router.replace({name: redirect || 'walletHome', query})
								}
							})
						}).finally(() => resolve(true))
					}
					
				})
			},
		}

	}
</script>
<style lang="scss" scoped>
  // @include fontStyle(#666, 24rpx);
	@mixin fontStyle($color, $size, $weight: 500) {
		color: $color;
		font-size: $size;
		font-weight: $weight;
	}
	.hd-pay-code-container{
		background-color: #fff;
		height: 100vh;
    padding: 80rpx 30rpx 0;
    .code-content{
      .code-txt{
        @include fontStyle(#3D3D3D, 32rpx);
        margin-bottom: 100rpx;
      }
    }
	}

</style>




